package com.example.blinkhome.util;

import java.util.ArrayList;

import android.content.Context;
import android.os.Handler;
import android.os.Message;
import com.orhanobut.logger.Logger;

public class SearchRoute {
	
	private Context mcontext;
	private String[] list;
	private Handler mHandler = new Handler(){

		public void handleMessage(android.os.Message msg) {

			switch (msg.what) {
			//IP列表获取完成
			case 0:
				String str = msg.obj.toString();
				Logger.d("ip==" + str);
				getIpList(str);
				break;
			default:
				break;
			}
		};
	};

	
	public SearchRoute(Context context) {
		// TODO Auto-generated constructor stub
		this.mcontext=context;
		//开始扫面IP
		startscanfif();
	}
	
	private void startscanfif(){
		//获取IP列表
		new Thread(new Runnable() {
			@Override
			public void run() {
				// TODO Auto-generated method stub
				String res = ndktool.scanfBlickRoute(mcontext);
				Message msg = new Message();
				msg.what = 0;
				msg.obj = res;
				mHandler.sendMessage(msg);
			}
		}).start();
	}
	
	private void getIpList(String ips){
		
		Logger.init();
		list=ips.split("@");
		for(int i=0;i<list.length;i++){
			Logger.d("list=="+list[i]);
			getDevicesInfo(list[i]);
		}
		
	}
	
	private void getDevicesInfo(String ip){
		
		try {
			String res=ndktool.getBlinkRouteInfo(ip);
			Logger.d("res=="+res);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		
	}

}
